// pages/mymessages/mymessages.js

Page({
  data: {
    messages: [
      {
        title: '系统通知',
        content: '您有一条新的系统通知，请注意查收。',
        time: ''
      },
      {
        title: '好友消息',
        content: '你的好友给你发送了一条消息，请查收。',
        time: ''
      },
      // Add more messages as needed
    ]
  },
  onLoad: function () {
    this.updateMessageTime();
  },
  updateMessageTime: function () {
    const messages = this.data.messages.map(message => {
      message.time = this.formatTime(new Date());
      return message;
    });
    this.setData({
      messages: messages
    });
    // Update time every minute
    setTimeout(this.updateMessageTime, 60000);
  },
  formatTime: function (date) {
    const year = date.getFullYear();
    const month = date.getMonth() + 1;
    const day = date.getDate();
    const hour = date.getHours();
    const minute = date.getMinutes();
    const second = date.getSeconds();
    return `${year}-${this.formatNumber(month)}-${this.formatNumber(day)} ${this.formatNumber(hour)}:${this.formatNumber(minute)}:${this.formatNumber(second)}`;
  },
  formatNumber: function (n) {
    n = n.toString();
    return n[1] ? n : '0' + n;
  }
})
